<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link type="text/css" rel="stylesheet" href="__PUBLIC__/css/style.css" />
    <!--[if IE 6]>
    <script src="__PUBLIC__/js/iepng.js" type="text/javascript"></script>
        <script type="text/javascript">
           EvPNG.fix('div, ul, img, li, input, a'); 
        </script>
    <![endif]-->
    
    <script type="text/javascript" src="__PUBLIC__/js/jquery-2.1.3.min.js"></script> 
    <script type="text/javascript" src="__PUBLIC__/js/menu.js"></script>    
                
	<script type="text/javascript" src="__PUBLIC__/js/n_nav.js"></script>   
    
    <script type="text/javascript" src="__PUBLIC__/js/num.js">
    	var jq = jQuery.noConflict();
    </script>     
    
    <script type="text/javascript" src="__PUBLIC__/js/shade.js"></script>
    
<title>数码商城</title>
</head>
<body>  
<!--Begin Header Begin-->
 <include file="./Public/page/header.html" />
<!--End Header End--> 
<!--Begin Menu Begin-->
<div class="menu_bg">
	<div class="menu">
    	<!--Begin 商品分类详情 Begin-->    
    	<div class="nav">
        	<div class="nav_t">全部商品分类</div>
            <div class="leftNav none">
                <ul>      
                     <volist name="t_list" id="t_list">  
                    <li>
                        <div class="fj">
                            <span class="n_img"><span></span><img src="__PUBLIC__/images/nav1.png" /></span>
                            <span class="fl">{$t_list.name}</span>
                        </div> 
                        <notempty name="t_list['lower']">
                       
                        <div class="zj">
                            <div class="zj_l">
                             <volist name="t_list[lower]" id="w_list">
                                <div class="zj_l_c">
                                    <h2><a href="{:U('Home/List/index',['id'=>$w_list['id']])}">{$w_list['name']}</a></h2>
                                    <notempty name="w_list['lower']">
                                    <volist name="w_list['lower']" id="e_list">
                                    <a href="{:U('Home/List/index',['id'=>$e_list['id']])}">{$e_list['name']}</a>|
                                    </volist>
                                    </notempty>
                                </div>
                            </volist>
                            </div>
                        
                        </div>
                        
                        </notempty>
                    </li>
                    </volist>
                </ul>            
            </div>
        </div>  
        <!--End 商品分类详情 End-->                                                     
    	<ul class="menu_r">    
		<!--导航栏-->
	    <include file="./Public/page/danhanglan.html" />	
        </ul>
    </div>
</div>
<!--End Menu End--> 
<div class="i_bg">  
    <div class="content mar_20">
    	<img src="__PUBLIC__/images/img1.jpg" />        
    </div>
    
    <!--Begin 第一步：查看购物车 Begin -->
    <div class="content mar_20">
    	<table border="0" class="car_tab" style="width:1200px; margin-bottom:50px;" cellspacing="0" cellpadding="0">
          <tr>
            <td class="car_th" width="490">商品名称</td>
            <td class="car_th" width="140">属性</td>
            <td class="car_th" width="150">购买数量</td>
            <td class="car_th" width="130">小计</td>
            <td class="car_th" width="140">返还积分</td>
            <td class="car_th" width="150">操作</td>
          </tr>
          <foreach name="list" item="val">
          <tr id = "buycar_tr{$val.id}" class="clear_bc">
            <td>
                <label class="r_rad"><input type="checkbox" id="status_{$val.id}" {$val['status']==1?checked:""} onclick="status({$val.id})" name="clear" /></label>
            	<div class="c_s_img"><img src="/TP/Uploads/comm/{$val['goodspic']}" width="73" height="73" /></div>
                {$val['goodsname']} 
            </td>
            <td align="center">颜色：{$val['color']}<br>内存：{$val['size']}</td>
            <td align="center">
            	<div class="c_num">
                    <input type="button" value="" id="buycar_jian{$val.id}" onclick="jianupdate({$val.id},{$val.price})" class="car_btn_1" />
                	<input type="text" id="bc_number{$val.id}" readonly value="{$val.number}" name="" class="car_ipt" />  
                    <input type="button" value="" onclick="jiaupdate({$val.id},{$val.price})" class="car_btn_2" />
                </div>
                
                <!-- onclick="jianUpdate1(jq(this)); -->
            </td>
            <td align="center" id="bc_total{$val.id}" style="color:#ff4e00;">￥{$val.total}</td>
            <td align="center" id = "bc_integral{$val.id}" >{$val.integral}</td>
           <!-- href="{:U('Home/Buycar/del_bc')}?id={$val['id']}"  -->
            <td align="center"><a onclick="buycar_del({$val.id})">删除</a>&nbsp; &nbsp;<a href="#" onclick="add_keep({$val.gid})">加入收藏</a></td>
            <!-- href="{:U('Home/Buycar/del_bc')}?id={$val['id']}" -->
          </tr>
          
          </foreach>
            
          <tr height="70">
          	<td colspan="6" style="font-family:'Microsoft YaHei'; border-bottom:0;">
            <!-- href="{:U('Home/Buycar/clear_bc')}?uid={$val.uid}" -->
            	<label class="r_rad"></label><label class="r_txt"><a onclick="clear_buycar({$val.uid})">清空购物车</a></label>
                <span class="fr">商品总价：￥<b id="buycar_total" style="font-size:22px; color:#ff4e00;">{$total}</b></span>
            </td>
          </tr>

          <tr valign="top" height="150">
          	<td colspan="6" align="right">
            	<a href="{:U('Home/Index/index')}"><img src="__PUBLIC__/images/buy1.gif" /></a>&nbsp; &nbsp; <a href="{:U('Home/Orders/index')}"><img src="__PUBLIC__/images/buy2.gif" /></a>
            </td>
          </tr>
        </table>
        <!-- 分页 -->
          <!-- <div align="right">{$show}</div> -->
    </div>
	<!--End 第一步：查看购物车 End--> 
    <!--Begin Footer Begin -->
	 <include file="./Public/page/footer.html" />
    <!--End Footer End -->    
</div>

</body>
<script>
    var jq = jQuery.noConflict();
    //设置商品总价
    // var total += parseInt(jq('.car_ipt').val());
    // alert(total);
    //减
    function jianupdate(id,price){
        // alert(id);
        // alert(number);
        //设置获取number值id
        var a = '#bc_number'+id;
        //设置total id
        var t = '#bc_total'+id;
        // alert(a);
        var i = '#bc_integral'+id;
        var integral = jq(i).html();
        var number = jq(a).val();
        jq.get("{:U('Home/Buycar/up_bc')}",{
            'id':id,
            'number':number,
            'price':price,
            'integral':integral
        },function(data){
            // alert(data);
            if(data > 0 ){
                //设置trid
                var p = '#buycar_tr'+id;
                if(number - 1 == 0){
                    jq(p).remove();
                     var total = jq('#buycar_total').html();
                    // alert(total);
                    total = parseInt(total);
                    // alert(total);
                    total = total - price;
                    // alert(total);
                    jq('#buycar_total').html(total)
                }else{
                    jq(a).val(number-1);
                    jq(t).html((number-1)*price);
                    var total = jq('#buycar_total').html();
                    // alert(total);
                    total = parseInt(total);
                    // alert(total);
                    total = total - price;
                    // alert(total);
                    // 拼接id
                    var integral = "#bc_integral"+id;
                    var inte = jq(integral).html();
                    inte = inte - 50;
                    jq(integral).html(inte);
                    jq('#buycar_total').html(total);
                    var status = "#status_"+id;
                    jq(status).attr('checked',"true");
                    
                }
                
            }
        });

    }
    //加
    function jiaupdate(id,price)
    {
        var a = '#bc_number'+id;
        //设置total id
        var t = '#bc_total'+id;
        // alert(a);
         var i = '#bc_integral'+id;
        var integral = jq(i).html();
        var number = jq(a).val();
        jq.get("{:U('Home/Buycar/up_bct')}",{
            'id':id,
            'number':number,
            'price':price,
            'integral':integral
        },function(data){
            // alert(data);
            if(data > 0 ){
                number = parseInt(number);
                var s = number+1;
                jq(a).val(s);
                jq(t).html(s*price);
                 var total = jq('#buycar_total').html();
                    // alert(total);
                    total = parseInt(total);
                    // alert(total);
                    total = total + price;
                    // alert(total);
                    jq('#buycar_total').html(total);
                    var integral = "#bc_integral"+id;
                    var inte = jq(integral).html();
                    inte = parseInt(inte);
                    inte = inte + 50;
                    jq(integral).html(inte);
                     var status = "#status_"+id;
                    jq(status).attr('checked',"true");

            }
        });

    }
    //删除操作
     function buycar_del(id){
        if(confirm('是否删除') == true){
            jq.get("{:U('Home/Buycar/del_bc')}",{'id':id},function(data){
                if(data == '删除成功'){
                    var buycar = "#buycar_tr"+id;
                    jq(buycar).remove();
                    jq.get("{:U('Home/Buycar/sec_total')}",function(data){
                        jq("#buycar_total").html(data);
                    });
                }else{
                    alert(data);
                }
            });
        }
    }
    //清空购物车操作
    function clear_buycar(uid){
        if(confirm('是否清空购物车') == true){
            jq.get("{:U('Home/Buycar/clear_bc')}",{'uid':uid},function(data){
                if(data == '清空购物车成功'){
                    jq(".clear_bc").remove();
                    jq("#buycar_total").html(0);
                }else{
                    alert(data);
                }
            });
        }
    }
    // 修改状态
    function status(id){
        jq.get("{:U('Home/buycar/by_status')}",{'id':id},function(data){
            var total = jq('#buycar_total').html();
            // alert(total);
            total = parseInt(total);
            data = parseInt(data);
            // alert(data);
            // console.log(typeof data);
            if(data < 0){
                var status = "#status_"+id;
                jq(status).removeAttr('checked');
            }
            total = total + data;
            jq('#buycar_total').html(total);
        });
    }
    //加入收藏
    function add_keep(id){
        var url = "{:U('Home/Keep/add_Keep')}";
        jq.get(url,{'id':id},function(data){
            alert(data);
        });
    }
</script>

<!--[if IE 6]>
<script src="__PUBLIC__///letskillie6.googlecode.com/svn/trunk/2/zh_CN.js"></script>
<![endif]-->
</html>
